<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>销售订单报表 - 766 SMART HOME</title>
<meta name="author" content="BIZ Team" />
<meta name="copyright" content="BIZ" />
<link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="path">
		<a href="${base}/admin/common/index.jhtml">${message("admin.path.index")}</a> &raquo; [#if reportType == 1]抬头视图[#elseif reportType == 2]项目视图[/#if]
	</div>
	<form id="listForm" action="list.jhtml" method="get">
		<div class="bar">
			<span>&nbsp;&nbsp;省：</span>
			<select name="provinceId" value="${provinceId}" class="option">
				<option value="">请选择</option>
				[#list provinces as pro]
					<option value="${pro.id}" [#if provinceId == pro.id]selected="selected"[/#if]>${pro.name}</option>
				[/#list]
			</select>
			<span>&nbsp;&nbsp;市/区：</span>
			<select name="cityId" value="${cityId}" class="option">
				<option value="">请选择</option>
				[#list citys as city]
					<option value="${city.id}" [#if cityId == city.id]selected="selected"[/#if]>${city.name}</option>
				[/#list]
			</select>
			<span>&nbsp;&nbsp;区：</span>
			<select name="areaId" value="${areaId}" class="option">
				<option value="">请选择</option>
				[#list areas as area]
					<option value="${area.id}" [#if areaId == area.id]selected="selected"[/#if]>${area.name}</option>
				[/#list]
			</select>
			<span>&nbsp;&nbsp;门店：</span>
			<input type="text" name="shopName" value="${shopName}" class="text"/>
			<span>&nbsp;&nbsp;下单日期：</span>
			<input type="text" id="beginDate" name="beginDate" style="width:120px" class="text Wdate" value="${beginDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'});">
			-<input type="text" id="endDate" name="endDate" style="width:120px" class="text Wdate" value="${endDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'});">
		</div>
		<div class="bar">
			<a href="javascript:;" id="exportBtn" class="button">导出Excel</a>
			<div class="buttonWrap">
				<a href="javascript:;" id="refreshButton" class="iconButton">
					<span class="refreshIcon">&nbsp;</span>${message("admin.common.refresh")}
				</a>
				<div class="menuWrap">
					<a href="javascript:;" id="pageSizeSelect" class="button">
						${message("admin.page.pageSize")}<span class="arrow">&nbsp;</span>
					</a>
					<div class="popupMenu">
						<ul id="pageSizeOption">
							<li>
								<a href="javascript:;"[#if page.pageSize == 10] class="current"[/#if] val="10">10</a>
							</li>
							<li>
								<a href="javascript:;"[#if page.pageSize == 20] class="current"[/#if] val="20">20</a>
							</li>
							<li>
								<a href="javascript:;"[#if page.pageSize == 50] class="current"[/#if] val="50">50</a>
							</li>
							<li>
								<a href="javascript:;"[#if page.pageSize == 100] class="current"[/#if] val="100">100</a>
							</li>
						</ul>
					</div>
				</div>
				<span>&nbsp;&nbsp;报表类型：</span>
				<select id="reportType" name="reportType" value="${reportType}" class="option">
					<option value="1" [#if reportType == 1]selected="selected"[/#if]>抬头视图</option>
					<option value="2" [#if reportType == 2]selected="selected"[/#if]>项目视图</option>
				</select>
				<span>&nbsp;&nbsp;<input type="submit" class="button" value="查询" /></span>
			</div>
		</div>
		<table id="listTable" class="list">
			[#if reportType == 1]
				<tr>
					<th><a href="javascript:;" class="sort" name="sn">销售订单号</a></th>
					<th><a href="javascript:;" class="sort" name="contract">客户合同号</a></th>
					<th><a href="javascript:;" class="sort" name="engineering">工程编号</a></th>
					<th><a href="javascript:;" class="sort" name="orderStatus">订单状态</a></th>
					<th><a href="javascript:;" class="sort" name="shops">下单门店</a></th>
					<th><a href="javascript:;" class="sort" name="serviceShops">服务门店</a></th>
					<th><a href="javascript:;" class="sort" name="">客户地区</a></th>
					<th><a href="javascript:;" class="sort" name="paymentStatus">付款方式</a></th>
					<th><a href="javascript:;" class="sort" name="paymentStatus">支付状态</a></th>
					<th><a href="javascript:;" class="sort" name="percent">已支付比例</a></th>
					<th><a href="javascript:;" >方案面积</a></th>
					<th><a href="javascript:;" class="sort" name="createDate">下单日期</a></th>
					<th><a href="javascript:;" class="sort" name="">下单门店奖励</a></th>
					<th><a href="javascript:;" class="sort" name="">服务门店奖励</a></th>
				</tr>
				[#if page.content?has_content]
					[#list page.content as order]
						<tr>
							<td>${order.sn}</td>
							<td>${order.contract}</td>
							<td>${order.engineering}</td>
							<td>
								[#if order.orderType == 1]
									${message("Order.OrderStatus." + order.orderStatus)}
								[#elseif order.orderType == 2]
									${message("Order.OrderStatus." + order.schemeStatus)}
								[/#if]
							</td>
							<td>${order.shops.shopsName}</td>
							<td>${order.serviceShops.shopsName}</td>
							<td>${order.area.fullName}</td>			
							<td>${order.paymentMethodName}</td>
							<td>${message("Order.PaymentStatus." + order.paymentStatus)}</td>
							<td class="[#if (order.percent < 60)]red[/#if]">
								${order.percent?string("0.##")}%
							</td>
							<td>
								[#if order.orderType == 2]
									${order.schemeArea+order.shopSchemeArea}平方米
								[/#if]
							</td>
							<td title="${order.createDate?string("yyyy-MM-dd hh:mm:ss")}">${order.createDate?string("yyyy-MM-dd")}</td>
							<td>${order.shopReward}</td>
							<td>${order.serviceReward}</td>
						</tr>
					[/#list]
				[/#if]
			[#elseif reportType == 2]
				<tr>
					<th><a href="javascript:;" class="sort" name="sn">销售订单号</a></th>
					<th><a href="javascript:;" class="sort" name="contract">订单类型</a></th>
					<th><a href="javascript:;" class="sort" name="engineering">订单行项目</a></th>
					<th><a href="javascript:;" class="sort" name="orderStatus">商品名称</a></th>
					<th><a href="javascript:;" class="sort" name="shops">商品编码</a></th>
					<th><a href="javascript:;" class="sort" name="serviceShops">订单数量</a></th>
					<th><a href="javascript:;" class="sort" name="">单位</a></th>
					<th><a href="javascript:;" class="sort" name="">订单单价(含税)</a></th>
					<th><a href="javascript:;" class="sort" name="">订单折扣</a></th>
					<th><a href="javascript:;" class="sort" name="paymentStatus">行项目总价(含税)</a></th>
					<th><a href="javascript:;" class="sort" name="shippingStatus">销项税金</a></th>
					<th><a href="javascript:;" class="sort" name="">下单门店奖励</a></th>
					<th><a href="javascript:;" class="sort" name="">服务门店奖励</a></th>
				</tr>
				[#if page.content?has_content]
					[#list page.content as order]
						[#--单品订单--]
						[#if order.orderType == 1]
							[#list order.orderItems as item]
								<tr>
									<td>${order.sn}</td>
									<td>单品订单</td>
									<td>${"00"+(item_index+1)}</td>
									<td title="${item.name}">${abbreviate(item.name,30,"...")}</td>
									<td>${item.sn}</td>
									<td>${item.quantity}</td>
									<td>${item.product.unit}</td>
									<td>${(item.price*item.proportions)?string("0.00")}</td>
									<td>0.00</td>
									<td>${(item.subtotal*item.proportions)?string("0.00")}</td>
									<td>[#if item.outputTax??]${item.outputTax?string("0.00")}[#else][/#if]</td>
									<td>${item.shopReward}</td>
									<td></td>
								</tr>
							[/#list]
						[#elseif order.orderType == 2]
							[#--方案订单--]
							<tr>
								<td>${order.sn}</td>
								<td>方案订单</td>
								<td>001</td>
								<td title="${order.schemeName}">${abbreviate(order.schemeName,30,"...")}</td>
								<td>${order.schemeSn}</td>
								<td>1</td>
								<td></td>
								<td>${order.amount?string("0.00")}</td>
								<td>${order.promotionDiscountScheme?string("0.00")}</td>
								<td>${order.amount?string("0.00")}</td>
								<td>[#if order.outputTax??]${order.outputTax?string("0.00")}[#else][/#if]</td>
								<td>${order.shopReward}</td>
								<td>${order.serviceReward}</td>
							</tr>
						[/#if]
					[/#list]
				[/#if]
			[/#if]
		</table>
		[@pagination pageNumber = page.pageNumber totalPages = page.totalPages]
			[#include "/admin/include/pagination.ftl"]
		[/@pagination]
	</form>
</body>
</html>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/list.js"></script>
<script type="text/javascript" src="${base}/resources/admin/datePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$().ready(function() {
		
		[@flash_message /]
		
		var $listForm = $("#listForm");
		var $reportType = $("#reportType");
		var $provinceId = $("select[name='provinceId']")
		var $cityId = $("select[name='cityId']")
		var $areaId = $("select[name='areaId']")
		var $exportBtn = $("#exportBtn");
		
		$reportType.change(function(){
			$listForm.submit();
		});
		
		//导出
		$exportBtn.click(function(){
			$.dialog({
				type: "warn",
				content: "您确认对所选查询进行数据导出吗?",
				onOk: function() {
					var shopName = $("input[name='shopName']").val();
					var createDate = $("#createDate").val();
					var beginDate = $("#beginDate").val();
					var endDate = $("#endDate").val();
					var provinceId = $provinceId.val();
					var cityId = $cityId.val();
					var areaId = $areaId.val();
					var exportType = $("#reportType").val();
					
					var data = "?shopName="+shopName+"&exportType="+exportType+"&beginDate="+beginDate+"&endDate="+endDate+"&provinceId="+provinceId+"&cityId="+cityId+"&areaId="+areaId;
					location.href="${base}/admin/orderReport/exportXlsToTotal.jhtml"+data;
				}
			});
		});
		
		
		//选择省
		$provinceId.change(function(){
			var proId = $provinceId.val();
			if(proId != null && proId != ""){
				findCitysByParentId(proId);
			}else{
				$cityId.empty();
				$areaId.empty();
				$cityId.append("<option value=''>请选择</option>");
				$areaId.append("<option value=''>请选择</option>");
				$areaId.removeAttr("disabled");
			}
		});
		//选择市
		$cityId.change(function(){
			var cityId = $cityId.val();
			if(cityId != null && cityId != ""){
				findAreasByParentId(cityId);
			}else{
				$areaId.empty();
				$areaId.append("<option value=''>请选择</option>");
			}
		});
	});
	
	//根据省id查询市
	function findCitysByParentId(proId){
		var $cityId = $("select[name='cityId']")
		var $areaId = $("select[name='areaId']")
		if(proId != null && proId != ""){
			$.ajax({
				url: "${base}/admin/orderReport/findCitysByParentId.jhtml",
				type: "post",
				data: {"parentId":proId},
				dataType: "json",
				cache: false,
				success: function(data) {
					if(data != null && data.length > 0){
						$cityId.empty();
						$areaId.empty();
						$cityId.append("<option value=''>请选择</option>");
						$areaId.append("<option value=''>请选择</option>");
						var htm = "";
						for(var i = 0 ; i < data.length ; i++){
							var city = data[i];
							htm += "<option value='"+city.id+"'>"+city.name+"</option>";
						}
						$cityId.append(htm);
					}
				},error:function(err){
					$.message("error","数据获取失败！");
				}
			});
		}
	}
	//根据市id查询区
	function findAreasByParentId(cityId){
		var $cityId = $("select[name='cityId']")
		var $areaId = $("select[name='areaId']")
		$areaId.removeAttr("disabled");
		if(cityId != null && cityId != ""){
			$.ajax({
				url: "${base}/admin/orderReport/findAreasByParentId.jhtml",
				type: "post",
				data: {"parentId":cityId},
				dataType: "json",
				cache: false,
				success: function(data) {
					if(data != null && data.length > 0){
						$areaId.empty();
						$areaId.append("<option value=''>请选择</option>");
						var htm = "";
						for(var i = 0 ; i < data.length ; i++){
							var area = data[i];
							htm += "<option value='"+area.id+"'>"+area.name+"</option>";
						}
						$areaId.append(htm);
					}else{
						$areaId.attr("disabled","disabled");
					}
				},error:function(err){
					$.message("error","数据获取失败！");
				}
			});
		}
	}
		
</script>